//
//  TPHttpTool.m
//  美丽说图片浏览器
//
//  Created by 唐鹏 on 16/7/13.
//  Copyright © 2016年 tangpeng. All rights reserved.
//

#import "TPHttpTool.h"


@implementation TPHttpTool

static TPHttpTool *_tool;
+ (instancetype)shareTool{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _tool = [[self alloc] init];
    });
    return _tool;
}

- (void)get:(void (^)(NSArray *result,NSError *error))result offset:(NSInteger)offset{
    self.manager = [AFHTTPSessionManager manager];
    NSString *url = [NSString stringWithFormat:@"http://mobapi.meilishuo.com/2.0/twitter/popular.json?offset=%zd&limit=30&access_token=b92e0c6fd3ca919d3e7547d446d9a8c2",offset];
    
    self.manager.responseSerializer = [AFJSONResponseSerializer new];
    
    self.manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json", nil];
    
    [self.manager GET:url parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary*  _Nullable responseObject) {
        
        NSArray* resultArray = responseObject[@"data"];
        //回调
        result(resultArray,nil);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",error);
        result(nil,error);
    }];
}

@end
